Home:ALL Converter>Compute fourier coefficients with Python?

Compute fourier coefficients with Python?

Ask Time:2018-11-12T13:15:00         Author:PCat27

Json Formatter

I'm trying to compute the following Fourier coefficients

enter image description here

where V_{pot} is a previous def function of this form. enter image description here

I really don't know what numerical method I can use, however I began with Simpson’s rule of scipy library.

import numpy as np
from scipy.integrate import simps

Nf = 200 
IVp = np.zeros(2*Nf)
snn = np.zeros(NP)
def f(k):
    for i in range(0,NP):
        sn = (i-1)*H
        snn[i] = sn
        return (1/SF) * np.cos(np.pi*k*sn/SF) * Vpot(sn)

 for k in range(0,2*Nf):
      Func = f(k)
      y1 = np.array(Func,dtype=float)
      I = simps(y1,snn)

I had this error:

IndexError: tuple index out of range

Author:PCat27,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53256277/compute-fourier-coefficients-with-python
yy